package com.qidian.k12.controller;

import com.qidian.k12.config.K12WenInit;
import com.qidian.k12.dto.PageInfo;
import com.qidian.k12.pojo.Admin;
import com.qidian.k12.service.AdminService;
import com.qidian.k12.util.K12Result;
import com.qidian.k12.util.ObjectTools;
import com.qidian.k12.vo.AdminQueryVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Admin)表控制层
 *
 * @author makejava
 * @since 2021-10-28 17:57:19
 */
@RestController
@RequestMapping("admin")
public class AdminController {
    /**
     * 服务对象
     */
    @Resource
    private AdminService adminService;

    @RequestMapping("/query")
    public PageInfo<Admin> query(AdminQueryVo vo){
       // System.out.println(vo);
        return  adminService.query(ObjectTools.object2map(vo));
    }

    @PostMapping("/save")
    public K12Result save(@RequestBody Admin admin){
        return K12Result.ok(adminService.insert(admin));
    }
    @PostMapping("/update")
    public K12Result update(@RequestBody Admin admin){
        return  adminService.update(admin);
    }
  @GetMapping("/get")
    public Admin get(Long adminId){
        return adminService.queryById(adminId);
  }

  @PostMapping("/login")
    public K12Result login(@RequestBody Admin admin){
        return adminService.login(admin.getAdminName(),admin.getAdminPass());
  }
  @GetMapping("/checkLogin")
    public K12Result checkLogin(String token){
        return adminService.checkLogin(token);
  }

}

